#! /usr/bin/env python
# -*- coding: utf-8 -*-

from operator import le
from re import S
from playwright.sync_api import Page
from ui_automation_test.common.base_page import BasePage
from ui_automation_test.locators.dualPrevention.riskCheckTaskManagement.hazardInvestigationPlan.hazardPlanList.loc_hazard_plan_list_search import LocSearchHazardPlanList
from ui_automation_test.locators.dualPrevention.riskCheckTaskManagement.hazardInvestigationPlan.hazardPlanList.loc_hazard_plan_list_view import LocViewHazardPlanList
from ui_automation_test.common.logger import logger


class HazardPlanList(BasePage):   

    def __init__(self, page: Page):
        super().__init__(page)
        self.switch_menu('双重预防机制')
        self.switch_menu('隐患排查任务管理')
        self.switch_menu('隐患排查计划')
        self.switch_menu('风险隐患排查计划')       
    
    def search_hazard_plan_list(self, company, object_name, unit_name, plan_status):
        """
        查询风险隐患排查计划
        :param company: 所属企业
        :param object_name: 所属风险分析对象
        :param unit_name: 所属风险分析单元        
        :param plan_status: 计划状态
        """
        logger.info('开始风险隐患排查计划查询')
        if company:
            logger.info(f'选择被排查企业: {company}')
            self.select(LocSearchHazardPlanList.loc_company_select, company)
        if object_name:
            logger.info(f'选择排查风险对象: {object_name}')
            self.select(LocSearchHazardPlanList.loc_object_select, object_name)
        if unit_name:
            logger.info(f'选择排查风险单元: {unit_name}')
            self.select(LocSearchHazardPlanList.loc_unit_name_select, unit_name)
        if plan_status:
            logger.info(f'选择计划状态: {plan_status}')
            self.select(LocSearchHazardPlanList.loc_plan_status_select, plan_status)
        logger.info('点击查询按钮')
        self.click(LocSearchHazardPlanList.loc_search_button)

    def view_hazard_plan(self, company, object_name, unit_name, plan_status):
        """
        查看风险隐患排查计划详情
        :param company: 所属企业
        :param object_name: 所属风险分析对象
        :param unit_name: 所属风险分析单元
        :param plan_status: 计划状态
        """
        logger.info('开始风险隐患排查任务查看')
        # 查询风险隐患排查任务
        self.page.wait_for_timeout(1000)
        logger.info('点击查看按钮')
        self.click(LocViewHazardPlanList.loc_view_button)
        logger.info('查看风险隐患排查任务详情')
        self.page.wait_for_timeout(6000)